﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Domain.Common;
using Domain.UserManagement;

namespace Application.UserManagement
{
    using Domain.UserManagement.Entities;
    using Application.Interfaces;

    public class UserManagementService : IUserManagementService
    {
        private readonly IUserRepository _userRepository;
        private readonly IRoleRepository _roleRepository;
        private readonly IUnitOfWork _unitOfWork;

        public UserManagementService(IUserRepository userRepository, IRoleRepository roleRepository, IUnitOfWork unitOfWork)
        {
            if(userRepository == null)
            {
                throw new ArgumentNullException("userRepository");
            }

            if(roleRepository == null)
            {
                throw new ArgumentNullException("roleRepository");
            }

            if(unitOfWork == null)
            {
                throw new ArgumentNullException("unitOfWork");
            }

            this._userRepository = userRepository;
            this._roleRepository = roleRepository;
            this._unitOfWork = unitOfWork;
        }

        public User AddUser(User newUser)
        {
            var item = this._userRepository.Add(newUser);

            this._unitOfWork.Save();

            return item;
        }

        public void UpdateUser(User changedUser)
        {
            throw new NotImplementedException();
        }

        public void DeleteUser(User removeUser)
        {
            this._userRepository.Delete(removeUser);
        }

        public IList<User> GetAllUsers()
        {
            var allUsers = this._userRepository.Get().ToList();

            return allUsers;

        }

        public User FindUser(string userName)
        {
            return _userRepository.Get(userName);
        }

        public Role AddRole(Role newRole)
        {
            var item = this._roleRepository.Add(newRole);

            this._unitOfWork.Save();

            return item;
        }

        public void UpdateRole(Role changedRole)
        {
            throw new NotImplementedException();
        }

        public void DeleteRole(Role removeRole)
        {
            throw new NotImplementedException();
        }

        public IList<Role> GetAllRoles()
        {
            var allRoles = this._roleRepository.Get().ToList();

            return allRoles;
        }

        public void AddPermission(Permission newPermission)
        {
            throw new NotImplementedException();
        }

        public void UpdatePermission(Permission changedPermission)
        {
            throw new NotImplementedException();
        }

        public void DeletePermission(Permission removePermission)
        {
            throw new NotImplementedException();
        }

        public IList<Permission> GetAllPermissions()
        {
            throw new NotImplementedException();
        }


        
    }
}
